
package com.putao.album.child;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.putao.album.R;
import com.putao.album.base.PtBaseAdapter;
import com.putao.album.child.bean.FamilyItem;
import com.putao.album.child.bean.RelationItem;
import com.putao.album.util.BitmapHelper;
import com.putao.album.util.Loger;
import com.putao.album.util.StringHelper;

import java.util.List;

/**
 * Created by chen on 15-5-5.
 */
public class ActivityFamilyAdapter extends PtBaseAdapter {
    public ActivityFamilyAdapter(Context context, List<FamilyItem> datalist) {
        super(context, datalist);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.activity_family_item, null);
            viewHolder = new ViewHolder();
            viewHolder.relation_icon = (ImageView) convertView.findViewById(R.id.relation_icon);
            viewHolder.relation_new = (ImageView) convertView.findViewById(R.id.relation_new);
            viewHolder.relation_name = (TextView) convertView.findViewById(R.id.relation_name);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        FamilyItem item = (FamilyItem) getItem(position);
        if(item.isNew()){
            viewHolder.relation_new.setVisibility(View.VISIBLE);
        }else {
            viewHolder.relation_new.setVisibility(View.INVISIBLE);
        }
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageForEmptyUri(RelationItem.Tag.getResIdByTag(item.getTag()))
                .showImageOnLoading(BitmapHelper.getLoadingDrawable()).showImageOnFail(BitmapHelper.getLoadingDrawable())
                .cacheOnDisk(true).cacheInMemory(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .considerExifParams(true)
                .build();
        ImageLoader.getInstance().displayImage(item.getAvatar(), viewHolder.relation_icon, options);

        viewHolder.relation_name.setText(item.getName());
        //Loger.d("chen++++getView():" + position);
        return convertView;
    }

    class ViewHolder {
        public ImageView relation_icon;
        public ImageView relation_new;
        public TextView relation_name;
    }
}
